namespace KTOP.Core.Netlists
{
    public class Pin
    {
        public Module Module { get; private set; }
        public int PinId { get; private set; }

        public Pin(int pin, Module module)
        {
            PinId = pin;
            Module = module;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Pin)) return false;

            return Equals((Pin) obj);
        }

        public bool Equals(Pin other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;

            return Module.Id == other.Module.Id && other.PinId == PinId;
        }

        public override int GetHashCode()
        {
            return (Module.Id << 16) + PinId;
        }

        public override string ToString()
        {
            return string.Format("{0}/{1}", Module.Id + 1, PinId + 1);
        }
    }
}